{% extends 'base.html' %} {% block css%}
<style type="text/css">
    .b1 {
        color: blue;
    }
</style>
{% endblock %} {% block body%}
<div class="row">

    <div class="col-md-8">
        <h4>命令控制台</h4>

		<table class="table table-hover table-condensed">
			<tr >
				<td>
<!-- 				<textarea id="debug_info" spellcheck="false" rows="24" cols="120" style="background-color:#FFFFCC; font-size: 12px"></textarea> -->

                <textarea class="form-control" id="debug_info" spellcheck="false" rows="10"  placeholder="" style="background-color:#FFFFCC; font-size: 12px"></textarea>

				</td>
			</tr>
			<tr>
				<td>
					<input class="form-control block" type="text" id="cmd_str" style="width:100%;height:32px" placeholder="">
                    <br><br>
                    <button class="btn btn-primary" id="btn_set_debug_cmd">
					发送命令
					</button>
					&nbsp;&nbsp;
					<button class="btn btn-success" id="btn_clear">
					清除信息
					</button>
				</td>
			</tr>
        </table>
        
        <div class="alert alert-info" role="alert">
        例如： 主界面数据及状态， 格式：55 02 EE AA
        </div>

    </div>

</div>

{% endblock %} {% block js%}
{{ super() }}
<script type="text/javascript">

function send_cmd()
{
    cmd_str = $("#cmd_str").val()
    console.log(cmd_str);

    $.post(
        "api/set_debug_cmdstr",
        {
            cmd_str:cmd_str
        },
        function(data,status){
            console.log("data: " + data);

            $("#debug_info").append(data.replace(/\\r\\n/g, "\n") + "\n");

            var textarea = document.getElementById('debug_info');
            textarea.scrollTop = textarea.scrollHeight;
            
    });
}

$(document).ready(function() {

    $("#btn_clear").click(function(){
        $("#debug_info").html("");
    })

    document.onkeydown = function(e){ 
        var ev = document.all ? window.event : e;
        if(ev.keyCode==13) {
            send_cmd();
        }
    }

    $("#btn_set_debug_cmd").click(function(){
        send_cmd();
    });

});
</script>
{% endblock %}